﻿using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Infrastructure.Imterfaces;
using AuthCenter_HuangJingtao.Read.Api.Application.Command.MenuaLL;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler.MenuaLL
{
    public class FirstRoleMenusCommandHandler : IRequestHandler<FirstRoleMenusCommand, ApiResult<RoleMenus>>
    {
        IBaseReponsitory<RoleMenus> RoleMenus;

        public FirstRoleMenusCommandHandler(IBaseReponsitory<RoleMenus> RoleMenus)
        {
            this.RoleMenus = RoleMenus;
        }

        public async Task<ApiResult<RoleMenus>> Handle(FirstRoleMenusCommand request, CancellationToken cancellationToken)
        {
            var list = await RoleMenus.GetQuery().FirstOrDefaultAsync(c => c.Role_Id == request.Role_Id);
            if (list != null)
            {
                return new ApiResult<RoleMenus>
                {
                    Code = ApiEnum.Success,
                    Message = "获取成功",
                    Data = list
                };
            }
            else 
            {
                return new ApiResult<RoleMenus>
                {
                    Code = ApiEnum.False,
                    Message = "获取失败",
                };
            }
      
        }
    }
}
